Description of the Installation and Upgrade of the Hi3521 SDK

Chapter 1 Description of the Upgrade of the Hi3521_SDK_Vx.x.x.x
   If you install the Hi3521 software development kit (SDK) for the first time, see chapter 2 "Initially Installing the Hi3521 SDK."
    
Chapter 2 Initially Installing the Hi3521 SDK
1. Locate the Hi3521 SDK.
    In Hi3521_V100R001***/01.software/board, you can find the file Hi3521_SDK_Vx.x.x.x.tgz. This file is the Hi3521 SDK.

2. Decompress the SDK.
    On a Linux server or a PC running a mainstream Linux operating system (OS), run the tar -zxf Hi3521_SDK_Vx.x.x.x.tgz command to decompress the SDK. Then the Hi3521_SDK_Vx.x.x.x folder is created.

3. Expand the SDK.
    Open the Hi3521_SDK_Vx.x.x.x folder, run ./sdk.unpack as the sudo or root user to display other compressed contents of the SDK by following instructions.
To copy the SDK on Windows, run ./sdk.cleanup to compress the SDK, copy the SDK to a new directory, and expand the SDK.

4. Install the cross compiler on a Linux server.
    1) Install the uclibc cross compiler (Note that you must have the sudo or root permission.)
       Go to the Hi3521_SDK_Vx.x.x.x/osdrv/toolchain/arm-hisiv100nptl-linux directory, run chmod +x cross.install, and run ./cross.install. 
    2) Install the glibc cross compiler (Note that you must have the sudo or root permission.)
       Go to the Hi3521_SDK_Vx.x.x.x/osdrv/toolchain/arm-hisiv200-linux directory, run chmod +x cross.install, and run ./cross.install. 
    3) Run source /etc/profile or log in to the server again for the environment variables to take effect. The environment variables are configured through the scripts that are used to install the cross compiler.

5. Compile osdrv
   Please read the <readme> in osdrv directory.

6. Description of the SDK directory
The structure of the Hi3521_SDK_Vx.x.x.x folder is as follows:    
    |-- sdk.cleanup                 #Cleanup scripts of the SDK.
    |-- sdk.unpack                  #Expansion scripts of the SDK.
    |-- osdrv                       #OS and related drivers
    |   |-- busybox                 # Source code of busybox
    |   |-- drv                     # Source code of drivers
    |   |-- kernel                  # Source code of the Linux kernel
    |   |-- pub                     # compiled images/tools/drivers
    |   |-- rootfs_scripts          # Root file system
    |   |-- toolchain               # cross compiler
    |   |-- tools                   # Source code of the Linux tools
    |   |-- uboot                   # Universal boot loader (U-boot) source code
    |   `-- Makefile                # osdrv Makefile
    |-- package                     #Compressed packages of the SDK
    |   |-- osdrv.tgz               #Compressed package of the linux and driver
    |   |-- mpp.tgz                 #Compressed package of the media processing platform (MPP) software
    |   `-- image                   #Images that can be burnt to the flash memory, such as the kernel or root file system
    |-- scripts                     #Shell scripts
    |-- mpp                         #MPP
        |-- component               #Component source code 
        |-- extdrv                  #Source code of the drivers of board-level peripherals
        |-- include                 #External header files
        |-- ko                      #Kernel driver
        |-- lib                     #Audio library and the library of the release version
        |-- tools                   #Tools used for media processing
        `-- sample                  #Source code samples


Chapter 3 Development Environment for Installing and Upgrading the U-boot on the Hi3521 Demo Board
    #If you use the Hi3521 demo board, perform the following steps to burn the U-boot, kernel, and file system. The items such as U-boot, kernel, and file system described in the following steps are updated in network mode.
    #Generally, the U-boot already exists on the board. If the U-boot does not exist in the board, you can to burn the U-boot to the board by using an emulator.
    #For details, see the Linux Development Environment User Guide in 01.software\board\documents.
    #In the following sections, it is assumed that the U-boot already exists on the board. The following describes how to burn the U-boot, kernel and rootfs to a flash memory over the Ethernet port.
    #The demo board boots from the NAND flash by default.
1. Configure the Trivial File Transfer Protocol (TFTP) server.
    #Copy the files in package/image_uclibc to the directory of a TFTP server.
    
2. Set parameters.
    After the board is powered on, press any key to start the U-boot. Set serverip (IP address of the FTFP server), ipaddr (IP address of the board), and ethaddr (media access control (MAC) address of the board) by running the following commands:
    setenv serverip xx.xx.xx.xx
    setenv ipaddr xx.xx.xx.xx 
    setenv ethaddr xx:xx:xx:xx:xx:xx
    setenv netmask xx.xx.xx.xx
    setenv gatewayip xx.xx.xx.xx
    Ping the IP address of the FTFP server to ensure that the network connection is normal.

3. Burn images to the SPI flash.
   In this section, a 16 MB SPI flash is used as an example.
1) Address space
        |      1M       |      4M       |     11M       |
        |---------------|---------------|---------------|
        |     boot      |     kernel    |     rootfs    |
        The following operations are performed based on the allocated address space. You can change the address space as required.
    2) Burn the U-boot.
        sf probe 0
        mw.b 82000000 ff 100000
        tftp 0x82000000 u-boot-Hi3521_930MHz.bin
        sf probe 0
        sf erase 0 100000
        sf write 82000000 0 100000	
        reset    
3) Burn the kernel.
        mw.b 82000000 ff 400000
        tftp 82000000 uImage
        sf probe 0
        sf erase 100000 400000
        sf write 82000000 100000 400000
4) Burn the file system.
        mw.b 82000000 ff b00000
        tftp 0x82000000 rootfs_256K.jffs2
        sf erase 500000 b00000
        sf write 82000000 500000 b00000
    4) Set boot parameters.
        setenv bootargs 'mem=64M console=ttyAMA0,115200 root=/dev/mtdblock2 rootfstype=jffs2 mtdparts=hi_sfc:1M(boot),4M(kernel),11M(rootfs)'
        setenv bootcmd 'sf probe 0;sf read 0x82000000 0x100000 0x400000;bootm 0x82000000'
        sa
4. Burn images to the NAND flash.
In this section, a 64 MB Nand flash[h1] is used as an example.
    1) Address space
        |      1M       |     15M       |     32M       |         16M            |
        |---------------|---------------|---------------|------------------------|
        |     boot      |    kernel     |    rootfs     |        other           
        The following operations are performed based on the allocated address space. You can change the address space as required.
    2) Burn the U-boot. 
        mw.b 82000000 ff 100000
        tftp 82000000 u-boot-Hi3521_930MHz.bin
        nand erase 0 100000
        nand write 82000000 0 100000
        reset
3) Burn the kernel.
        mw.b 82000000 ff f00000
        tftp 82000000 uImage
        nand erase 100000 f00000
        nand write 82000000 100000 f00000
4) Burn the file system.
        mw.b 82000000 ff 2000000
        tftp 82000000 rootfs_2k_1bit.yaffs2
        nand erase 1000000 2000000
        nand write.yaffs 82000000 1000000 95b980    #Note: 95b980 indicates the actual size of the rootf file system, and is a hexadecimal number.
    4) Set boot parameters.
	setenv bootargs 'mem=64M console=ttyAMA0,115200 root=/dev/mtdblock2 rootfstype=yaffs2 mtdparts=hinand:1M(boot),15M(kernel),32M(rootfs),16M(test)'
        setenv bootcmd 'nand read 0x82000000 0x100000 0x500000;bootm 0x82000000'
        sa
5 Start the new system.
    reset	#Restart to enter the new system.

Chapter 4 Preparing the Development Environment
Pin multiplexing
    #The .sh script in mpp/ko_hi3521 is used to configure the multiplexing relationships between the pins related to media services. You can change the multiplexing relationships as required. The script is called by load3521, and is executed before the MPP kernel driver is loaded.
    #The multiplexing relationships of other pins are configured in the U-boot. For details, see the U-boot Porting Development Guide.
    
Chapter 5 Using the SDK and Demo Board for Development
1 Enable the network on Linux.
    # Set network parameters.
    ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx;
    ifconfig eth0 xx.xx.xx.xx netmask xx.xx.xx.xx;
    route add default gw xx.xx.xx.xx
    #Ping another machine. If the ping operation is successful, the network works properly.

2. Use the network file system (NFS) for development.
    #You are advised to use the NFS as the development environment. This ensures that you do not need to create and burn the root file system again.
    #Mount the NFS by running the following command:
    mount -t nfs -o nolock -o tcp xx.xx.xx.xx:/your-nfs-path /mnt
    #Access the files in the server under /mnt, and develop related products or solution.

3 Enable the telnet service.
    # After the network works properly, run the telnetd& command to enable the telnet service of the board, and connect to the board over telnet.

4 Run the MPP services.
    #On the board running the Linux OS, go to the mpp/ko_hi3521 directory, and load the .ko file.
    cd mpp/ko_hi3521
    ./load3521 -i
    
    #Go to the sample directories, run the samples that are compiled successfully on the server.
    cd mpp/sample/vio
    ./sample_vio 0
    
Chapter 6 Allocating and Using the Address Space
1. Double-data rate (DDR) memory management
    1) The DDR memory is classified into the OS memory and media memory zone (MMZ) memory. The OS memory is managed by the OS, and the MMZ memory is managed by the MMZ kernel module (mmz.ko in mpp/ko_hi35xx), and is available only for media services.
    2) The start address of the OS memory is 0x80000000. The memory size can be changed by setting bootargs. For example, the parameter "setenv bootargs 'mem=64M ... " described in chapter 3 indicates that the OS memory is 64 MB. You can change the OS memory as required.
    3) When the MMZ kernel module is loaded, the start address and size of the MMZ memory can be specified by setting parameters. For example:
    insmod mmz.ko mmz=anonymous,0,0x84000000,442M:jpeg,0,0x9fa00000,5M anony=1 || report_error
    The MMZ memory is divided into two parts. The first part is named anonymous. Its start address is 0x84000000, and its size is 442 MB. The second part is named jpeg. Its start address is 0x9fa00000, and its size is 5 MB. You can change the start address and memory size by specifying the MMZ parameters in the load3521 script in mpp/ko_hi35XX.
    4) The address ranges of the MMZ memory and OS memory cannot overlap.

2. Memory management for the DDR on the demo board
    The following is an example using the 512 MB DDR. The default memory configurations are as follows:
    DDR:                                                           
    
    -----|-------|  0x80000000   # Memory managed by OS.              
    64M  | OS    |                                                 
         |       |                                                 
    -----|-------|  0x84000000   # Memory managed by MMZ block anonymous.          
    442M | MMZ   |                                                 
         |       |                                                 
    -----|-------|  0x9fa00000   # Memory managed by MMZ block jpeg.                       
    5M   |       |                                                 
         |       |                                                 
    -----|-------|  0x9FF00000   # Not used.                         
    1M   |       |                                                 
         |       |                                                 
    -----|-------|  0xA0000000   # End of DDR.                  
                                                                                                                          
Note:                                                                                                                     
	(1) Set the size of the memory managed by the OS to 64 MB by running setenv bootargs 'mem=64M ... when setting boot parameters.	  
	(2) After the system starts, set the sizes of the memories managed by the MMZ to 447 MB  by running insmod mmz.ko mmz=anonymous,0,0x84000000,442M:jpeg,0,0x9fa00000,5M anony=1 || report_error in the load3521 script.    